using System.Runtime.CompilerServices;

namespace Nsb
{
    [IgnoreNamespace]
    public static partial class Transform
    {
        [AlternateSignature]
        public static extern string Htmlize(string txt);

        public static string Htmlize(string txt, bool pass)
        {
            if (pass) return txt;
            string ot = "";
            string c;
            for (int i = 0; i < txt.Length; i++)
            {
                c = txt.Substr(i, 1);
                switch (c)
                {
                    case "<":
                        ot += "&lt;";
                        break;
                    case ">":
                        ot += "&gt;";
                        break;
                    case "&":
                        ot += "&amp;";
                        break;
                    case "\n":
                        ot += "<br/>";
                        break;
                    case " ":
                        ot += "&nbsp;";
                        break;
                    //case "\t":
                    //ot += "&nbsp;&nbsp;&nbsp;&nbsp;";
                    //break;
                    //case "\r": // This is/was a bug in Script#
                    //break;
                    default:
                        ot += c;
                        break;
                }
            }
            return ot;
        }
    }
}